function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
} 

function openforgetpass()
{

 $('.ovlPopGen').fadeOut();
 $('.wrpPopFP').fadeIn();
 
 
 
}
function readCookie(name) {
            var nameEQ = name + "=";
            var ca = document.cookie.split(';');
            for (var i = 0; i < ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0) == ' ') c = c.substring(1, c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
            }
            return null;
        }
function openlogin()
{
 $('.ovlPopGen').fadeOut();
 $('.wrpPopLI').fadeIn();
 
}


$('#fromforgetpass').submit(function() {



var checkerror=new Array();
var rowerror=0;
var datasend={};
if($("#forget-email").val()=="")
{
    
     checkerror[rowerror++]={msg:"Please request field input",code:4,obj:$("#forget-email")};
     

}else
{
    if(validateEmail($("#forget-email").val()))
    {
    datasend['email']=$("#forget-email").val();
    
    }

}








if(checkerror.length==0)
{
loaddata();
$.post(serviceinfo+"forgetpassword",datasend,
function(data){
loadclosedata();
if(data.error.response)
{
alertboxtext(data.error.error,$("#validateerror-forget"));

}else
{
$('.wrpPopFP .desLS.clTxt2.fs04').html('We send new password to your email already.<br />Please check your email address.');
$('.wrpPopFP .goBackFgt.clTxt2').remove();
$('.wrpPopFP .goBack.clSp1').html('go back to login page');
$('#fromforgetpass').remove();

//location.href=baseinfo;


}


});


}else
{

alertboxtext(checkerror,$("#validateerror-forget"));

}












return false;



});

$('#fromlogin').submit(function() {



var checkerror=new Array();
var rowerror=0;
var datasend={};
var cookieset=readCookie('redirectto'); 

cookieset='/'+cookieset

if($("#login-username").val()=="")
{
    
     checkerror[rowerror++]={msg:"Please request field input",code:4,obj:$("#login-username")};
     

}
else
{
    if(validateEmail($("#login-username").val()))
    {
    datasend['email']=$("#login-username").val();
    
    }else
    {
    datasend['username']=$("#login-username").val();
    
    }

}

if($("#login-password").val()=="")
{

    checkerror[rowerror++]={msg:"Please request field input",code:4,obj:$("#login-password")};

}
else
{
    datasend['password']=$("#login-password").val();


}


if($("#fromlogin #rem").is(':checked'))
{
datasend['rememberme']=1;
//console.log(datasend);
//return false;

}
 
 

if(checkerror.length==0)
{
loaddata();
$.post(serviceinfo+"login",datasend,
function(data){
loadclosedata();
if(data.error.response)
{
alertboxtext(data.error.error,$("#validateerror-login"));

}else
{

location.href=baseinfo+cookieset;


}


});


}else
{

alertboxtext(checkerror,$("#validateerror-login"));

}












return false;



});


$('#fromsignup').submit(function() {
var checkerror=new Array();
var rowerror=0;
if($('#fromsignup input[name="username"]').val()=="")
{
    
     checkerror[rowerror++]={msg:"Please insert Username",code:4,obj:$("#validateerror-signup")};
     $('#fromsignup input[name="username"]').focus();

}
if($('#fromsignup input[name="email"]').val()=="")
{
    
     checkerror[rowerror++]={msg:"Please insert Email",code:4,obj:$("#validateerror-signup")};
     $('#fromsignup input[name="email"]').focus();

}

if($('#fromsignup input[name="password"]').val()=="")
{
    
     checkerror[rowerror++]={msg:"Please insert Password",code:4,obj:$("#validateerror-signup")};
     $('#fromsignup input[name="password"]').focus();

}
//console.log($('#fromsignup input[name="agreecheck"]').is(":checked"));

if(!$('#fromsignup input[name="agreecheck"]').is(":checked"))
{
    
     checkerror[rowerror++]={msg:"Please Check Agree",code:4,obj:$("#validateerror-signup")};


}

if(rowerror==0)
{
loaddata();
$.post(serviceinfo+"signup",$('#fromsignup').serialize(),
function(data){
loadclosedata();
if(data.error.response)
{
alertboxtext(data.error.error,$("#validateerror-signup"));

}else
{

$(".showsignup").hide();
$(".showsignupsucess").show();



}



});

return false;
}
else
{
//console.log(checkerror);
alertboxtext(checkerror,$("#validateerror-signup"));
}
return false;
});



